//
//  PassportViewController.m
//  ProfilePicture
//
//  Created by 张云江 on 2019/10/14.
//  Copyright © 2019年 张云江. All rights reserved.
//

#import "PassportViewController.h"
#import "HomeCollectionViewCell.h"

static NSString *cellId = @"Passport_Identifier";

@interface PassportViewController () <UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView  *ordinaryCollectionView;
@property (nonatomic, strong) NSMutableArray    *headArray;

@end

@implementation PassportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)creatUI
{
    self.customNavBar.hidden = YES;
    self.headArray = [NSMutableArray array];
    
    HomeInfoMode *info = [[HomeInfoMode alloc] init];
    [info setSizeW:602 withSizeH:602 withName:@"美国签证" withSizeDes:@"602 x 602 px" withSpecId:119];
    [self.headArray addObject:info];
    HomeInfoMode *info1 = [[HomeInfoMode alloc] init];
    [info1 setSizeW:531 withSizeH:531 withName:@"日本签证" withSizeDes:@"531 x 531 px" withSpecId:541];
    [self.headArray addObject:info1];
    HomeInfoMode *info2 = [[HomeInfoMode alloc] init];
    [info2 setSizeW:472 withSizeH:708 withName:@"越南签证" withSizeDes:@"472 x 708  px" withSpecId:543];
    [self.headArray addObject:info2];
    HomeInfoMode *info3 = [[HomeInfoMode alloc] init];
    [info3 setSizeW:413 withSizeH:531 withName:@"入台证" withSizeDes:@"413 x 531 px" withSpecId:577];
    [self.headArray addObject:info3];
    HomeInfoMode *info4 = [[HomeInfoMode alloc] init];
    [info4 setSizeW:389 withSizeH:566 withName:@"电子护照人像照片" withSizeDes:@"389 x 566 px" withSpecId:434];
    [self.headArray addObject:info4];
    HomeInfoMode *info5 = [[HomeInfoMode alloc] init];
    [info5 setSizeW:389 withSizeH:566 withName:@"海外申请护照在线预约照片" withSizeDes:@"389 x 566 px" withSpecId:435];
    [self.headArray addObject:info5];
    HomeInfoMode *info6 = [[HomeInfoMode alloc] init];
    [info6 setSizeW:551 withSizeH:709 withName:@"世界通用签证" withSizeDes:@"551 x 709 px" withSpecId:435];
    [self.headArray addObject:info6];
    HomeInfoMode *info7 = [[HomeInfoMode alloc] init];
    [info7 setSizeW:389 withSizeH:566 withName:@"港澳通行证" withSizeDes:@"389 x 566 px" withSpecId:71];
    [self.headArray addObject:info7];
    HomeInfoMode *info8 = [[HomeInfoMode alloc] init];
    [info8 setSizeW:551 withSizeH:709 withName:@"韩国签证" withSizeDes:@"551 x 709 px" withSpecId:116];
    [self.headArray addObject:info8];
    HomeInfoMode *info9 = [[HomeInfoMode alloc] init];
    [info9 setSizeW:551 withSizeH:708 withName:@"泰国签证" withSizeDes:@"551 x 708 px" withSpecId:114];
    [self.headArray addObject:info9];
    HomeInfoMode *info10 = [[HomeInfoMode alloc] init];
    [info10 setSizeW:602 withSizeH:602 withName:@"印度签证" withSizeDes:@"602 x 602 px" withSpecId:141];
    [self.headArray addObject:info10];
    HomeInfoMode *info11 = [[HomeInfoMode alloc] init];
    [info11 setSizeW:602 withSizeH:602 withName:@"以色列签证" withSizeDes:@"602 x 602 px" withSpecId:201];
    [self.headArray addObject:info11];
    HomeInfoMode *info12 = [[HomeInfoMode alloc] init];
    [info12 setSizeW:354 withSizeH:472 withName:@"签证采集" withSizeDes:@"354 x 472 px" withSpecId:518];
    [self.headArray addObject:info12];
    HomeInfoMode *info13 = [[HomeInfoMode alloc] init];
    [info13 setSizeW:551 withSizeH:709 withName:@"入台证" withSizeDes:@"551 x 709 px" withSpecId:577];
    [self.headArray addObject:info13];
    HomeInfoMode *info14 = [[HomeInfoMode alloc] init];
    [info14 setSizeW:551 withSizeH:709 withName:@"马来西亚签证" withSizeDes:@"551 x 709 px" withSpecId:162];
    [self.headArray addObject:info14];
    HomeInfoMode *info15 = [[HomeInfoMode alloc] init];
    [info15 setSizeW:897 withSizeH:1204 withName:@"新西兰签证" withSizeDes:@"897 x 1204 px" withSpecId:511];
    [self.headArray addObject:info15];
    HomeInfoMode *info16 = [[HomeInfoMode alloc] init];
    [info16 setSizeW:413 withSizeH:472 withName:@"意大利签证" withSizeDes:@"413 x 472 px" withSpecId:136];
    [self.headArray addObject:info16];
    HomeInfoMode *info17 = [[HomeInfoMode alloc] init];
    [info17 setSizeW:472 withSizeH:472 withName:@"阿根廷签证" withSizeDes:@"472 x 472 px" withSpecId:150];
    [self.headArray addObject:info17];
    HomeInfoMode *info18 = [[HomeInfoMode alloc] init];
    [info18 setSizeW:472 withSizeH:590 withName:@"巴西,冰岛签证" withSizeDes:@"472 x 590 px" withSpecId:578];
    [self.headArray addObject:info18];
    HomeInfoMode *info19 = [[HomeInfoMode alloc] init];
    [info19 setSizeW:590 withSizeH:590 withName:@"肯尼亚签证" withSizeDes:@"590 x 590 px" withSpecId:174];
    [self.headArray addObject:info19];
    HomeInfoMode *info20 = [[HomeInfoMode alloc] init];
    [info20 setSizeW:413 withSizeH:531 withName:@"入金证" withSizeDes:@"413 x 531 px" withSpecId:174];
    [self.headArray addObject:info20];
    
    self.view.backgroundColor = kUIColorFromRGB(0xF3F5FF);
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.minimumInteritemSpacing = kRatio(2);
    layout.minimumLineSpacing = kRatio(20);
    layout.footerReferenceSize = CGSizeMake(kScreenWidth, kRatio(40));
    CGFloat itemW = (kScreenWidth - kRatio(80))/2;
    CGFloat itemH = itemW;
    
    layout.itemSize = CGSizeMake(itemW, itemH);
    self.ordinaryCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(kRatio(30), 0, self.view.frame.size.width - kRatio(60), kScreenHeight - kRatio(260)) collectionViewLayout:layout];
    [self.ordinaryCollectionView registerClass:[UICollectionView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeadCollectionView"];
    [self.ordinaryCollectionView registerClass:[HomeCollectionViewCell class] forCellWithReuseIdentifier:cellId];
    self.ordinaryCollectionView.backgroundColor = [UIColor clearColor];
    self.ordinaryCollectionView.showsVerticalScrollIndicator = NO;
    self.ordinaryCollectionView.delegate = self;
    self.ordinaryCollectionView.dataSource = self;
    [self.view addSubview:self.ordinaryCollectionView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView
     numberOfItemsInSection:(NSInteger)section
{
    return self.headArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId
                                                                             forIndexPath:indexPath];
    HomeInfoMode *info = self.headArray[indexPath.row];
    [cell updateInfo:info];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomeInfoMode *info = self.headArray[indexPath.row];
    self.onCellClick(info);
}
@end
